package pattern.decorator;

public class DecoratorPatternDemo {
    public static void main(String[] args) {
        Person person = new Person("jack");
        Tshirt t = new Tshirt();
        t.show();
        t.Decorator(person);
        t.show();
        System.out.println("_____");
        Jeans j = new Jeans();
        j.Decorator(t);
        j.show();
    }
}
 class Person {
    private String name;
    public Person(String name) {
        this.name = name;
    }
    public Person() {}
    public void show() {
        System.out.println("装扮的"+name);
    }
}
//
 class Decorator extends Person{
    protected Person person;
    public void Decorator(Person person) {
        this.person = person;
    }
    public Decorator() {}
    public void show() {
        if(person != null) {
            person.show();
        }
    }
}
//
 class Jeans extends Decorator{

    public Jeans() {
    }
    @Override
    public void show() {
        System.out.println("牛仔裤");
        super.show();
    }
}
 class Tshirt extends Decorator{

    public Tshirt() {
    }
    @Override
    public void show() {
        System.out.println("T恤");
        super.show();
    }

}
